<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./libs/vue.js"></script>
</head>
<body>
    <div id="app">
        <table border="1" width="300" height="200">
            <tr>
                <th></th>
                <th>id</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>操作</th>
            </tr>
            <!-- 
                key值作用：
                    在数据层和视图层建立一个一一对应关系，方便状态保持
             -->
            <tr v-for="(item,index) in stuList" :key="item.id">
                <td>
                    <input type="checkbox">
                </td>
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.age}}</td>
                <td>
                    <button @click="del(index)">删除</button>
                </td>
            </tr>
        </table>
    </div>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                stuList:[
                    {
                        id:1,
                        name:'张三',
                        age:20
                    },
                    {
                        id:2,
                        name:'李四',
                        age:22
                    },
                    {
                        id:3,
                        name:'王五',
                        age:21
                    },
                ]
            },
            methods: {
                del(index) {
                    console.log(index)
                    // 删除
                    this.stuList.splice(index,1)
                }
            },
        })
    </script>
</body>
</html>